package filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter("/*")
public class CrosFilter implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        //允许所有的域名
        ((HttpServletResponse)response).setHeader("Access-Control-Allow-Origin","*");
        ((HttpServletResponse)response).setHeader("Access-Control-Allow-Credentials","*");
        ((HttpServletResponse)response).setHeader("Access-Control-Allow-Methods","*");
        ((HttpServletResponse)response).setHeader("Access-Control-Max-Age","3000");
        ((HttpServletResponse)response).setHeader("Access-Control-Allow-Headers","Authorization,Origin,X-Requested-With,Content-Type,"+
                "Accept,content-Type,origin,x-requested-with,content-type,accept,authorization,token,id,X-Custom-Header,X-Cookie,Connection,User-Agent,Cookie,*");
        ((HttpServletResponse)response).setHeader("Access-Control-Request-Headers","Authorization,Origin,X-Requested-With,content-Type,Accept,Token");
        chain.doFilter(request, response);
    }
}
